Array.prototype.random = function () { return this[Math.floor((Math.random()*this.length))]; } const TIER1 = ['US', 'CA', 'NZ', 'AU', 'UK']; const TIER3 = ['IN','CN','ID','PK','CG','CD', 'BD', 'PH', 'EG', 'BR']; //default smartlink in case country can't be resolved const fallBackSmartlink = 'https://google.com/'; const offers = { 'https://google.com/': [...TIER1, 'DE'], //all tier1 countries + germany 'https://bing.com/': ['LT', 'EE', 'LV'], //just all baltic states 'https://duckduckgo.com/': [...TIER3, 'UK'], //all tier3 countries + United Kingdom }; async function handleRequest(request) { let redirectTo = fallBackSmartlink; let country = request.cf ? request.cf.country : '404'; let links = []; for(const offer in offers){ if( offers[offer].includes(country) ){ links.push(offer); } } if( links.length ){ redirectTo = links.random(); } //variant #1, redirect to smartlink without referrer //html becauce we want privacy and keep referrer hidden const html = `